package com.help10000.rms.ui.windows

import android.content.Context
import android.content.Intent
import android.net.Uri
import com.amir.common.beans.MapNavigationData
import com.amir.common.holder.CommonViewHolder
import com.amir.common.utils.AppUtils
import com.amir.common.utils.ToastUtil
import com.lxj.xpopup.XPopup
import com.tencent.map.geolocation.TencentLocation

class SelectNavigationMapDialog(
    context: Context,
    data: MapNavigationData,
    tencentLocation: TencentLocation?
) {
    var holder: CommonViewHolder? = null
    var data: MapNavigationData? = null
    var tencentLocation: TencentLocation? = null
    var mContext: Context = context

    init {
        this.data = data
        this.tencentLocation = tencentLocation
    }

    fun show() {
        val location = data?.location
        XPopup.Builder(mContext).asBottomList(
            "",
            arrayOf("百度地图", "腾讯地图", "高德地图")
        ) { position, text ->
            when (position) {
                1 -> {
                    if (!AppUtils.isAvilible(mContext, "com.tencent.map")) {
                        ToastUtil.show("请先安装腾讯地图APP")
                        return@asBottomList
                    }
                    val uri = Uri.parse(
                        "qqmap://map/routeplan?type=drive"//路线规划方式参数：公交：bus 驾车：drive 步行：walk 骑行：bike
                                + "&from=${tencentLocation?.name}"
                                + "&fromcoord=${tencentLocation?.latitude},${tencentLocation?.longitude}"
                                + "&to=" + data?.title//终点的显示名称 必要参数
                                + "&tocoord=" + location?.lat + "," + location?.lng//终点的经纬度
                                + "&referer=7SCBZ-JC3WD-PHA45-HDZ7Q-DY5AH-NPBYQ"
                    )
                    val intent = Intent()
                    intent.setData(uri);
                    mContext.startActivity(intent);
                }
                2 -> {
                    if (!AppUtils.isAvilible(mContext, "com.autonavi.minimap")) {
                        ToastUtil.show("请先安装高德地图APP")
                        return@asBottomList
                    }
                    val uri =
                        Uri.parse("amapuri://route/plan/?dlat=" + "${location?.lat}" + "&dlon=" + "${location?.lng}" + "&dname=" + "${data?.address}" + "&dev=0&t=0");
                    mContext.startActivity(Intent(Intent.ACTION_VIEW, uri));
                }
                0 -> {
                    if (!AppUtils.isAvilible(mContext, "com.baidu.BaiduMap")) {
                        ToastUtil.show("请先安装百度地图APP")
                        return@asBottomList
                    }
                    val location = data?.location
                    var uri =
                        Uri.parse("baidumap://map/direction?destination=latlng:" + "目的地lat" + "," + "目的地lng" + "|name:" + "目的地名称" + "&mode=driving");

                    uri =
                        Uri.parse("baidumap://map/marker?location=${location?.lat},${location?.lng}&title=${data?.title}&content=${data?.address}&traffic=on&src=andr.baidu.openAPIdemo");
                    mContext.startActivity(Intent(Intent.ACTION_VIEW, uri))

                }


            }

        }.show()
    }


}